<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Interoperating with Java Lucene - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.search.lucene.java-lucene.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.search.lucene.java-lucene.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.search.lucene.extending.html">Extensibility</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.search.lucene.html">Zend_Search_Lucene</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.search.lucene.advanced.html">Advanced</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.search.lucene.java-lucene" class="section"><div class="info"><h1 class="title">Interoperating with Java Lucene</h1></div>
    

    <div class="section" id="zend.search.lucene.index-creation.file-formats"><div class="info"><h1 class="title">File Formats</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Search_Lucene</span> index file formats are binary compatible with
            Java Lucene version 1.4 and greater.
        </p>

        <p class="para">
            A detailed description of this format is available here:
            <tt class="uri">http://lucene.apache.org/java/2_3_0/fileformats.html</tt>
            <a href="#fnid1" name="fn1"><sup>[1]</sup></a>
                
            .
        </p>
    </div>

    <div class="section" id="zend.search.lucene.index-creation.index-directory"><div class="info"><h1 class="title">Index Directory</h1></div>
        

        <p class="para">
            After index creation, the index directory will contain several files:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    The <var class="filename">segments</var> file is a list of index segments.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    The <var class="filename">*.cfs</var> files contain index segments.
                    Note! An optimized index always has only one segment.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    The <var class="filename">deletable</var> file is a list of files that are no longer
                    used by the index, but which could not be deleted.
                </p>
            </li>
        </ul>
    </div>

    <div class="section" id="zend.search.lucene.java-lucene.source-code"><div class="info"><h1 class="title">Java Source Code</h1></div>
        

        <p class="para">
            The Java program listing below provides an example of how to index a file
            using Java Lucene:
        </p>

        <pre class="programlisting brush: java">
/**
* Index creation:
*/
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.document.*;

import java.io.*

...

IndexWriter indexWriter = new IndexWriter(&quot;/data/my_index&quot;,
                                          new SimpleAnalyzer(), true);

...

String filename = &quot;/path/to/file-to-index.txt&quot;
File f = new File(filename);

Document doc = new Document();
doc.add(Field.Text(&quot;path&quot;, filename));
doc.add(Field.Keyword(&quot;modified&quot;,DateField.timeToString(f.lastModified())));
doc.add(Field.Text(&quot;author&quot;, &quot;unknown&quot;));
FileInputStream is = new FileInputStream(f);
Reader reader = new BufferedReader(new InputStreamReader(is));
doc.add(Field.Text(&quot;contents&quot;, reader));

indexWriter.addDocument(doc);
</pre>

    </div>
<div class="footnote"><a name="fnid1" href="#fn1"><sup>[1]</sup></a><span class="para footnote">
                    The currently supported Lucene index file format version is 2.3 (starting from
                    Zend Framework 1.6).
                </span></div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.search.lucene.extending.html">Extensibility</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.search.lucene.html">Zend_Search_Lucene</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.search.lucene.advanced.html">Advanced</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.search.lucene.html">Zend_Search_Lucene</a></li>
  <li><a href="zend.search.lucene.overview.html">Overview</a></li>
  <li><a href="zend.search.lucene.index-creation.html">Building Indexes</a></li>
  <li><a href="zend.search.lucene.searching.html">Searching an Index</a></li>
  <li><a href="zend.search.lucene.query-language.html">Query Language</a></li>
  <li><a href="zend.search.lucene.query-api.html">Query Construction API</a></li>
  <li><a href="zend.search.lucene.charset.html">Character Set</a></li>
  <li><a href="zend.search.lucene.extending.html">Extensibility</a></li>
  <li class="active"><a href="zend.search.lucene.java-lucene.html">Interoperating with Java Lucene</a></li>
  <li><a href="zend.search.lucene.advanced.html">Advanced</a></li>
  <li><a href="zend.search.lucene.best-practice.html">Best Practices</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>